//
//  MaintenceDetailCell.m
//  PropertyMananger
//
//  Created by bh on 17/2/8.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "MaintenceDetailCell.h"

@implementation MaintenceDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
+ (CGFloat)cellMoreHeightWiht:(MaintenanceDetailModel *)model
{
    //展开后得高度(计算出文本内容的高度+固定控件的高度)
    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:15]};
    NSStringDrawingOptions option = (NSStringDrawingOptions)(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading);
    CGSize size = [model.text boundingRectWithSize:CGSizeMake(BHscreenW - 30, MAXFLOAT) options:option attributes:attribute context:nil].size;;
    
    if(size.height < 30){
        size.height = 30;
    }
    return size.height + 20;
}


+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"MaintenceDetailCellID";
    MaintenceDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    cell.idexPath = indexPath;
    if(cell == nil) {
        cell = [[MaintenceDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    //选中cell的颜色 -无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.nameLabel];
        
        self.nameLabel.textColor = BHColor(102, 102, 102);
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel.numberOfLines = 0;
        self.nameLabel.font = BHFont(14);
        self.nameLabel.text  = @"设备名称:";
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(15);
            make.centerY.equalTo(self).with.offset(0);
            make.right.mas_offset(-15);
            
        }];
        
        
    }
    return self;
}

-(void)setDetailModel:(MaintenanceDetailModel *)detailModel{
    _detailModel = detailModel;
    self.nameLabel.text = detailModel.text;
    
    NSRange  rang = [detailModel.text rangeOfString:@":"];
    DLog(@"%ld---%ld",rang.length ,rang.location);
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:detailModel.text];
    [string addAttribute:NSForegroundColorAttributeName value:BHColor(51, 51, 51) range:NSMakeRange(rang.location,detailModel.text.length-rang.location)];
    
    self.nameLabel.attributedText = string;
    
        if(self.idexPath.section == 0){
            if(self.idexPath.row == 0){
    
            }
    
        }else if (self.idexPath.section == 1){
        
            if (self.idexPath.row == 2) {
                
              
            }
        
        }
    
    
    
}
@end
